﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace CTEA_INDIA
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            

            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (Session["UserId"] == null || Session["UserId"].ToString() == "")
            {
                Session.Abandon();
                Session.RemoveAll();
                Response.Redirect("Default.aspx");
            }
          

        }




       
        public void Clear()
        {
            txtPass.Text = "";
            txtNewPassword.Text = "";
            txtConfirm.Text = "";
        }

        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            int userid = Convert.ToInt32(Session["UserID"]);
            int login = Convert.ToInt32(Session["login"]);
            string EncriptedPasswd = BAL.Encryption.Encript(txtPass.Text, "&%#@?,:*");
            string EncriptedNewPasswd = BAL.Encryption.Encript(txtNewPassword.Text, "&%#@?,:*");

            string strIDUser = BAL.Customers.ChangePassword(userid, login, EncriptedPasswd, EncriptedNewPasswd);

            if (strIDUser == "-1")
            {
                idSpanMsg.Style.Add("display", "block");
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "changeCSSClass", "<script type=\"text/javascript\">$('#idSpanMsg').addClass('spanErrorMsgs');</script>", true);

                idSpanMsg.InnerHtml = "Sorry!!  Password you entered is incorrect";

            }
            else
            {
                idSpanMsg.Style.Add("display", "block");
                idSpanMsg.InnerHtml = "Your Password is Changed Successfully.....";
                Clear();
            }
        }
    }
}
